USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Insert]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Insert record into table [dbo].[DealersTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Insert]
	/*@DealerType_RowNumber int =Null OUTPUT , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerType_ParentID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@DealerType_Notes varchar(max) =Null  , 
	@DealerType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[DealersTypes](/*[DealerType_ID], [DealerType_ParentID], [DealerTypeCode], [DealerType_NameAr], [DealerType_NameEn], [DealerType_Notes], [DealerType_Search]*/)
	VALUES     (/*@DealerType_ID, @DealerType_ParentID, @DealerTypeCode, @DealerType_NameAr, @DealerType_NameEn, @DealerType_Notes, @DealerType_Search*/)

	/*SELECT @DealerType_RowNumber = [DealerType_RowNumber]
    FROM [dbo].[DealersTypes]
    WHERE  ( [DealerType_ID] =@DealerType_ID )
	AND  ( [DealerType_ParentID] =@DealerType_ParentID )
	AND  ( [DealerTypeCode] =@DealerTypeCode )
	AND  ( [DealerType_NameAr] =@DealerType_NameAr )
	AND  ( [DealerType_NameEn] =@DealerType_NameEn )
	AND  ( [DealerType_Notes] =@DealerType_Notes )
	AND  ( [DealerType_Search] =@DealerType_Search )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-update]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Update record in table [dbo].[DealersTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-update]
	/*@DealerType_RowNumber int =Null OUTPUT , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerType_ParentID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@DealerType_Notes varchar(max) =Null  , 
	@DealerType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[DealersTypes] SET 
		/*[DealerType_ID] =@DealerType_ID, 
		[DealerType_ParentID] =@DealerType_ParentID, 
		[DealerTypeCode] =@DealerTypeCode, 
		[DealerType_NameAr] =@DealerType_NameAr, 
		[DealerType_NameEn] =@DealerType_NameEn, 
		[DealerType_Notes] =@DealerType_Notes, 
		[DealerType_Search] =@DealerType_Search*/
		/*WHERE ([DealerType_ID] = @DealerType_ID)*/
	/**/

	/*SELECT @DealerType_RowNumber = [DealerType_RowNumber]
    FROM [dbo].[DealersTypes]
	WHERE ([DealerType_ID] = @DealerType_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Insert-Update]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Insert OR Update record into table [dbo].[DealersTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Insert-Update]
	/*@DealerType_RowNumber int =Null OUTPUT , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerType_ParentID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@DealerType_Notes varchar(max) =Null  , 
	@DealerType_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[DealersTypes] 
					/*WHERE ([DealerType_ID] = @DealerType_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[DealersTypes](/*[DealerType_ID], [DealerType_ParentID], [DealerTypeCode], [DealerType_NameAr], [DealerType_NameEn], [DealerType_Notes], [DealerType_Search]*/)
		VALUES     (/*@DealerType_ID, @DealerType_ParentID, @DealerTypeCode, @DealerType_NameAr, @DealerType_NameEn, @DealerType_Notes, @DealerType_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[DealersTypes] SET 
			/*[DealerType_ID] =@DealerType_ID, 
			[DealerType_ParentID] =@DealerType_ParentID, 
			[DealerTypeCode] =@DealerTypeCode, 
			[DealerType_NameAr] =@DealerType_NameAr, 
			[DealerType_NameEn] =@DealerType_NameEn, 
			[DealerType_Notes] =@DealerType_Notes, 
			[DealerType_Search] =@DealerType_Search*/
			/*WHERE ([DealerType_ID] = @DealerType_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @DealerType_RowNumber = [DealerType_RowNumber]
    FROM [dbo].[DealersTypes]
	WHERE ([DealerType_ID] = @DealerType_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Delete]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	delete records from table [dbo].[DealersTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Delete]
	/*@DealerType_RowNumber int =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@DealerType_ParentID uniqueidentifier =null  , 
	@DealerTypeCode varchar(50) =null  , 
	@DealerType_NameAr varchar(300) =null  , 
	@DealerType_NameEn varchar(300) =null  , 
	@DealerType_Notes varchar(max) =null  , 
	@DealerType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[DealersTypes]
	WHERE /*( [DealerType_RowNumber] = ISNULL(@DealerType_RowNumber, [DealerType_RowNumber]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [DealerType_ParentID] = ISNULL(@DealerType_ParentID, [DealerType_ParentID]) )
	AND ( [DealerTypeCode] like ISNULL(@DealerTypeCode, [DealerTypeCode]) )
	AND ( [DealerType_NameAr] like ISNULL(@DealerType_NameAr, [DealerType_NameAr]) )
	AND ( [DealerType_NameEn] like ISNULL(@DealerType_NameEn, [DealerType_NameEn]) )
	AND ( [DealerType_Notes] like ISNULL(@DealerType_Notes, [DealerType_Notes]) )
	AND ( [DealerType_Search] like ISNULL(@DealerType_Search, [DealerType_Search]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Select]    Script Date: [[20120714223933]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223933]]
-- Description:	select records from table [dbo].[DealersTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Select]
	/*@DealerType_RowNumber int =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@DealerType_ParentID uniqueidentifier =null  , 
	@DealerTypeCode varchar(50) =null  , 
	@DealerType_NameAr varchar(300) =null  , 
	@DealerType_NameEn varchar(300) =null  , 
	@DealerType_Notes varchar(max) =null  , 
	@DealerType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[DealersTypes]
	WHERE /*( [DealerType_RowNumber] = ISNULL(@DealerType_RowNumber, [DealerType_RowNumber]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [DealerType_ParentID] = ISNULL(@DealerType_ParentID, [DealerType_ParentID]) )
	AND ( [DealerTypeCode] like ISNULL(@DealerTypeCode, [DealerTypeCode]) )
	AND ( [DealerType_NameAr] like ISNULL(@DealerType_NameAr, [DealerType_NameAr]) )
	AND ( [DealerType_NameEn] like ISNULL(@DealerType_NameEn, [DealerType_NameEn]) )
	AND ( [DealerType_Notes] like ISNULL(@DealerType_Notes, [DealerType_Notes]) )
	AND ( [DealerType_Search] like ISNULL(@DealerType_Search, [DealerType_Search]) )*/
END
GO
-- =============================================
